package com.hotel.controller;

import com.hotel.entity.Orders;
import com.hotel.response.MessageUtils;
import com.hotel.response.RestResponse;
import com.hotel.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 夏智力
 * @FileName OrderController
 * @date 2021/6/23 8:01
 * @Software: IntelliJ IDEA
 */

@RestController
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    // 根据userId查询订单
    @RequestMapping(path = "/order/userList", method = RequestMethod.GET)
    public RestResponse selectUserOrder(int userId) {
        List<Orders> userOrders = ordersService.selectOrderByUserId(userId);
        return MessageUtils.success(userOrders);
    }

    // 添加订单
    @RequestMapping(path = "/order/add", method = RequestMethod.POST)
    public void addOrder(Orders order) {
        ordersService.addOrder(order);
    }

    // 修改订单状态
    @RequestMapping(path = "/order/update", method = RequestMethod.POST)
    public void updateStatus(int id, int status) {
        ordersService.updatePayStatus(id, status);
    }
}
